package com.iplay.web.version.mobile;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.iplay.service.version.mobile.MobileAppVersionService;
import com.iplay.vo.version.mobile.PostMobileAppVersionVO;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@RestController
@RequestMapping("/api/mobile")
public class MobileVersionController {
	@Autowired
	private MobileAppVersionService appVersionService;
	
	@ApiOperation(notes = "获得安卓的版本，返回一个double", value = "")
	@GetMapping("/android/version")
	//@PreAuthorize("hasRole('DEVELOPER')")
	public double getVersionOfAndroid() {
		return appVersionService.getAndroidAppVersion();
	}
	
	@ApiOperation(notes = "获得ios的版本，返回一个double", value = "")
	@GetMapping("/ios/version")
	//@PreAuthorize("hasRole('DEVELOPER')")
	public double getVersionOfIOS() {
		return appVersionService.getIOSAppVersion();
	}
	
	@ApiOperation(notes = "具有DEVELOPER权限的用户修改安卓的版本", value = "")
	@PutMapping("/android/version")
	@PreAuthorize("hasRole('DEVELOPER')")
	public double updateVersionOfAndroid(@ApiParam("包含版本信息的实体") 
	@Valid @RequestBody PostMobileAppVersionVO vo) {
		return appVersionService.setAndroidAppVersion(vo.getVersion());
	}
	
	@ApiOperation(notes = "具有DEVELOPER权限的用户修改IOS的版本", value = "")
	@PutMapping("/ios/version")
	@PreAuthorize("hasRole('DEVELOPER')")
	public double updateVersionOfIOS(@ApiParam("包含版本信息的实体") @Valid @RequestBody PostMobileAppVersionVO vo) {
		return appVersionService.setIOSAppVersion(vo.getVersion());
	}
	
}
